package com.alex.springboot;

import com.alex.springboot.mapper.PrivilegeMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;

@SpringBootApplication
@MapperScan(basePackageClasses = {PrivilegeMapper.class})
public class SpringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ac) {
        return args -> {
            System.out.println("看看springboot为我们注入了哪些bean");

            String[] beanNames = ac.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (int i=1;i<=beanNames.length;i++) {
                System.out.println(String.format("%s. %s", i, beanNames[i-1]));
            }
        };
    }

}
